//
//  27. 移除元素.swift
//  LeetCodeTrain
//
//  Created by rjb on 2021/7/10.
//  Copyright © 2021 rjb. All rights reserved.
//

import Foundation
class Solution27 {
    func removeElement(_ nums: inout [Int], _ val: Int) -> Int {
        var slow = -1
        for item in nums {
            if item != val {
                slow += 1
                nums[slow] = item
            }
        }
        return slow + 1
    }
    static func test() {
        let solution = Solution27()
        var nums =  [0,1,2,2,3,0,4,2]
        let val = 2
        let result = solution.removeElement(&nums, val)
        print(result)
    }
}
